﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace syc.ZhiJian
{
    public partial class 产品理化参数录入 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            if (LuHao0.Text == "")
            {
                this.Message.Text = ".请输入炉号！";
                return;
            }
            try
            {
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();
                //判断该炉号存不存在产品库存中，如果不存在则不能保存理化参数
                DataSet ds = new DataSet();
                string sql = "select * from 产品库存 where 炉号='" + this.LuHao0.Text.Trim() + "'";
                SqlDataAdapter sda = new SqlDataAdapter(sql, Conn);
                sda.Fill(ds);
                int rowCount = ds.Tables[0].Rows.Count;
                if (rowCount == 0)
                {
                    this.Message.Text = ".该炉号不存在库存中！";
                    return;
                }
                else
                {
                    SqlCommand Cmd = new SqlCommand();
                    Cmd.Connection = Conn;

                    Cmd.CommandText = "理化参数";
                    Cmd.CommandType = CommandType.StoredProcedure;
                    Cmd.Parameters.Add(new SqlParameter("@产品ID", SqlDbType.Int, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, Request.QueryString["ChanPin"]));
                    Cmd.Parameters.Add(new SqlParameter("@炉号", SqlDbType.NVarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.LuHao0.Text));
                    Cmd.ExecuteNonQuery();
                    SqlCommand Cmd1 = new SqlCommand();
                    Cmd1.Connection = Conn;
                    Cmd1.CommandText = @"INSERT INTO [产品理化参数]
           ([产品ID]
           ,[炉号]
           ,[C]
           ,[Mn]
           ,[Si]
           ,[P]
           ,[S]
           ,[Cr]
           ,[Ni]
           ,[Cu]
           ,[Mo]
           ,[Al]
           ,[V]
           ,[Bi]
           ,[Sn]
           ,[Pb]
           ,[As]
           ,[Sb]
           ,[抗拉强度]
           ,[屈服极限]
           ,[伸长率]
           ,[横向冲击]
           ,[纵向冲击]
           ,[通径检验]
           ,[静水压试验]
           ,[无损探伤]
           ,[表面检验]
           ,[尺寸])
     VALUES(" + Request.QueryString["ChanPin"] + ",'" + this.LuHao0.Text + "','" +
                      C.Text + "','" + Mn.Text + "','" + Si.Text + "','" + P.Text + "','" + S.Text + "','" +
                      Cr.Text + "','" + Ni.Text + "','" + Cu.Text + "','" + Mo.Text + "','" + Al.Text + "','" +
                      V.Text + "','" + Bi.Text + "','" + Sn.Text + "','" + Pb.Text + "','" + As.Text + "','" +
                      Sb.Text + "','" + klqd.Text + "','" + qsjx.Text + "','" + scl.Text + "','合格','合格','合格','合格','合格','合格','合格')";
                    Cmd1.ExecuteNonQuery();

                    this.Message.Text = ".操作成功！";
                }
            }
            catch (Exception ex)
            {
                this.Message.Text = ex.Message;
            }

        }

        protected void Button_ReNew_Click(object sender, EventArgs e)
        {
            this.LuHao0.Text = "";
            C.Text = "";
            Mn.Text = "";
            Si.Text = "";
            P.Text = "";
            S.Text = "";
            Cr.Text = "";
            Ni.Text = "";
            Cu.Text = "";
            Mo.Text = "";
            Al.Text = "";
            V.Text = "";
            Bi.Text = "";
            Sn.Text = "";
            Pb.Text = "";
            As.Text = "";
            Sb.Text = "";
            klqd.Text = "";
            qsjx.Text = "";
            scl.Text = "";
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
